package com.xqls.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.xqls.biz.DictionaryBiz;
import com.xqls.biz.DischargeRealdataBiz;
import com.xqls.biz.FluggasDischargeRealdataBiz;
import com.xqls.biz.IntakeRealdataBiz;
import com.xqls.biz.PublicStormwaterRealdataBiz;
import com.xqls.biz.RainwaterDischargeRealdataBiz;
import com.xqls.util.CommonPage;
import com.xqls.util.CommonResult;
import com.xqls.util.DictionaryEnums;
import com.xqls.util.GetKeyByValue;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping(value = "/realdata")
public class RealdataController {
	@Autowired
	private RainwaterDischargeRealdataBiz rainwaterBiz;
	@Autowired
	private PublicStormwaterRealdataBiz publicBiz;
	@Autowired
	private DischargeRealdataBiz discharBiz;
	@Autowired
	private IntakeRealdataBiz intakeBiz;
	@Autowired private FluggasDischargeRealdataBiz fluggasBiz;

	@Autowired private DictionaryBiz dictionaryBiz;
//实时数据历史记录
	@RequestMapping(value = "/{tablename}/realdataList")
	public ModelAndView realdataList(@PathVariable(value = "tablename") String tablename) {
		ModelAndView view = new ModelAndView("Realdata/realdataList");
		String url = null;
		String title = null;
		Map<Integer, String> map = dictionaryBiz.queryDictionaryByParent(DictionaryEnums.COMPANY_TYPE.getCode());
		if (tablename.equals("intake")) {
			url = "/realdata/IntakeListData";
			title = "取水口实时数据";
			view.addObject("deviceType", GetKeyByValue.getKey(map, "取水口"));
			view.addObject("count",intakeBiz.queryAll());
		} else if (tablename.equals("discharge")) {
			url = "/realdata/DischargelistData";
			title = "排放口实时数据";
			view.addObject("deviceType", GetKeyByValue.getKey(map, "排放口"));
			view.addObject("count",discharBiz.queryAll());
		} else if (tablename.equals("rainwater")) {
			url = "/realdata/RainwaterDischargeRealdata";
			title = "企业雨水排放口实时数据";
			view.addObject("deviceType", GetKeyByValue.getKey(map, "企业雨水排放口"));
			view.addObject("count",rainwaterBiz.queryAll());
		} else if (tablename.equals("stormwater")) {
			url = "/realdata/PublicStormwaterRealdata";
			title = "公共雨水排放口实时数据";
			view.addObject("deviceType", GetKeyByValue.getKey(map, "公共雨水排放口"));
			view.addObject("count",publicBiz.queryAll());
		}
 else if (tablename.equals("fluggas")) {
			url = "/realdata/FluggasDischargeRealdata";
			title = "废气排放口实时数据";
			view.addObject("deviceType", GetKeyByValue.getKey(map, "废气排放口"));
			view.addObject("count",fluggasBiz.getAll());
		}
		view.addObject("columns", CommonPage.setColumnToPage(null,
				null, url, title));
		view.addObject("tablename",tablename);
		return view;
	}

	@RequestMapping("/IntakeListData")
	@ResponseBody
	public CommonResult intakeListData(@RequestBody CommonPage commonPage, HttpServletRequest request, HttpServletResponse response) {
		CommonResult commonResult = intakeBiz.queryIntakeRealdata(commonPage,request,response);//完成
		if (commonResult.getIsSuccess()) {
			commonResult.setData(commonPage);
		}
		
		return commonResult;
	}

	@RequestMapping("/DischargelistData")
	@ResponseBody
	public CommonResult discharListData(@RequestBody CommonPage commonPage, HttpServletRequest
			request, HttpServletResponse response) {
		CommonResult commonResult = discharBiz.queryDischargeRealdata(commonPage,request,response);
		if (commonResult.getIsSuccess()) {
			commonResult.setData(commonPage);

		}

		return commonResult;
	}

	@RequestMapping("/PublicStormwaterRealdata")
	@ResponseBody
	public CommonResult PublicStormwaterRealdata(@RequestBody CommonPage commonPage, HttpServletRequest request, HttpServletResponse response) {
		CommonResult commonResult = publicBiz.queryPublicStormwaterRealdata(commonPage,request,response);
		if (commonResult.getIsSuccess()) {
			commonResult.setData(commonPage);

		}

		return commonResult;
	}

	@RequestMapping("/RainwaterDischargeRealdata")
	@ResponseBody
	public CommonResult RainwaterDischargeRealdata(@RequestBody CommonPage commonPage, HttpServletRequest request, HttpServletResponse response) {
		CommonResult commonResult = rainwaterBiz.queryRainwaterDischargeRealdata(commonPage,request,response);
		if (commonResult.getIsSuccess()) {
			commonResult.setData(commonPage);

		}

		return commonResult;
	}

	@RequestMapping("/FluggasDischargeRealdata")
	@ResponseBody
	public CommonResult FluggasDischargeRealdata(@RequestBody CommonPage commonPage, HttpServletRequest request, HttpServletResponse response) {
		CommonResult commonResult = this.fluggasBiz.getListByPage(commonPage,request,response);
		if (commonResult.getIsSuccess()) {
			commonResult.setData(commonPage);
		}
		return commonResult;
	}
}
